package cn.josh.action;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.josh.bean.Ec_shopcar;
import cn.josh.service.Ec_shopcarService;
import cn.josh.servicelmpl.Ec_shopcarServiceImpl;


@WebServlet("/ArticleCarWriteServlet")
public class ArticleCarWriteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		//得到session对象
		HttpSession session = request.getSession();
		
		//得到用户id
		String userId = (String)session.getAttribute("userId");
		System.out.println("用户id是：" + userId);
		//得到商品id
		String articleId = (String)session.getAttribute("articleId");
		System.out.println("商品id是：" + articleId);
		//得到商品数量
		String count = (String)request.getParameter("count");
		System.out.println("商品数量是：" + count);
		
		//将商品封装
		Ec_shopcar shopcar = new Ec_shopcar();
		shopcar.setUserId(userId);
		shopcar.setArticleId(articleId);
		shopcar.setBuyNum(count);
		
		//调用数据库服务
		Ec_shopcarService shopSer = new Ec_shopcarServiceImpl();
		shopSer.insertShop(shopcar);
		
		
		response.sendRedirect("/ShoppingWebsite/ArticleCarReadServlet");	
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{

		doGet(request, response);
	}

}
